//
//  XMLNode.m
//  Alfresco
//
//  Created by Michael Muller on 8/22/09.
//  Copyright 2010 Zia Consulting.  Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php 
//

#import "XMLNode.h"


@implementation XMLNode

@synthesize children;
@synthesize attributes;
@synthesize tagName;
@synthesize body;

- (id) init {
	[super init];

	children = [[NSMutableArray alloc] init];
	attributes = [[NSDictionary alloc] init];
	body = [[NSMutableString alloc] init];
	
	return self;
}

- (void) dealloc {
	[children release];
	[attributes release];
	[body release];
	[tagName release];
	[super dealloc];
}

- (void) addChild:(XMLNode *) child {
	[children addObject: child];
}

- (NSString *) dumpToString:(NSMutableString *)str indent:(int)indent {
	for (int i = 0; i < indent; i++) {
		[str appendString: @"  "];
	}
	[str appendString: self.tagName];
	for (NSString *key in attributes) {
		[str appendString: @" "];
		[str appendString: key];
		[str appendString: @"="];
		[str appendString: [attributes objectForKey:key]];
	}
	[str appendString: @"\n"];
	for (XMLNode *child in children) {
		[child dumpToString:str indent:(indent+2)];
	}
	return str;
}

- (void) appendStringToBody:(NSString *) str {
	[body appendString:str];
}

@end
